package ophiux.common.net;

import ophiux.api.sdk.OphiuxApiException;
import ophiux.common.utils.HttpUtil;

public class WebserviceApiRequest implements INetApiRequest {

	@Override
	public String request(String serviceURL, String methodName, String StrParam) 
			throws OphiuxApiException {
		 return request(serviceURL, methodName, StrParam,30*1000);
	}

	@Override
	public String request(String serviceURL, String methodName, String StrParam,
			int timeOut)throws OphiuxApiException {
		String response = null;
		try {
			response = HttpUtil.httpsRequest(serviceURL, methodName, StrParam, timeOut);
			response = response.replaceAll("&lt;", "<");
		    response = response.replaceAll("&gt;", ">");
			response = response.replaceAll("<return>", "%");
			response = response.replaceAll("</return>", "%");; 
			response = response.replaceAll("&quot;", "\"");
			String[] body = response.split("%");
			response = body[1];
			response = response.replaceAll("&#xD;", "");
		} catch (Exception e) {
			throw new OphiuxApiException(e);
		}
		return response;
	}

	public static void main(String[] args) {
		WebserviceApiRequest d= new WebserviceApiRequest();
		String param = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:wec='http://wechatpay.ophiux.com/'><soapenv:Header/><soapenv:Body><wec:micropay><data>{ 'mch_token':'b05f2a23-3286-459a-9ed3-599c9a8b93b0','device_info':'2','nonce_str':'3','sign':'600EC6955C2EC7B715997C676B1F1C29','sign_type':'MD5','body':'刷卡支付测试','out_trade_no':'288039692945782107','fee_type':'CNY','total_fee':'300','pay_type':'alipay','spbill_create_ip':'192.168.6.89','limit_pay':'no_credit','auth_code':'288039692945782107','cashier':'','attach':'暂无'}</data></wec:micropay></soapenv:Body></soapenv:Envelope>";
		try {
			String response = d.request("http://9a73f221.ngrok.io/OphiuxWeChatPay1.2/ws/service?wsdl","GET",param);
			
			
			System.out.println(response);
		} catch (OphiuxApiException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
